package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TChange;
import com.ruoyi.system.service.ITChangeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宿舍调换Controller
 * 
 * @author fyk
 * @date 2024-05-10
 */
@RestController
@RequestMapping("/system/change")
public class TChangeController extends BaseController
{
    @Autowired
    private ITChangeService tChangeService;

    /**
     * 查询宿舍调换列表
     */
    @PreAuthorize("@ss.hasPermi('system:change:list')")
    @GetMapping("/list")
    public TableDataInfo list(TChange tChange)
    {
        startPage();
        List<TChange> list = tChangeService.selectTChangeList(tChange);
        return getDataTable(list);
    }

    /**
     * 导出宿舍调换列表
     */
    @PreAuthorize("@ss.hasPermi('system:change:export')")
    @Log(title = "宿舍调换", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TChange tChange)
    {
        List<TChange> list = tChangeService.selectTChangeList(tChange);
        ExcelUtil<TChange> util = new ExcelUtil<TChange>(TChange.class);
        util.exportExcel(response, list, "宿舍调换数据");
    }

    /**
     * 获取宿舍调换详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:change:query')")
    @GetMapping(value = "/{changeId}")
    public AjaxResult getInfo(@PathVariable("changeId") Long changeId)
    {
        return success(tChangeService.selectTChangeByChangeId(changeId));
    }

    /**
     * 新增宿舍调换
     */
    @PreAuthorize("@ss.hasPermi('system:change:add')")
    @Log(title = "宿舍调换", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TChange tChange)
    {
        return toAjax(tChangeService.insertTChange(tChange));
    }

    /**
     * 修改宿舍调换
     */
    @PreAuthorize("@ss.hasPermi('system:change:edit')")
    @Log(title = "宿舍调换", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TChange tChange)
    {
        return toAjax(tChangeService.updateTChange(tChange));
    }

    /**
     * 删除宿舍调换
     */
    @PreAuthorize("@ss.hasPermi('system:change:remove')")
    @Log(title = "宿舍调换", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeIds}")
    public AjaxResult remove(@PathVariable Long[] changeIds)
    {
        return toAjax(tChangeService.deleteTChangeByChangeIds(changeIds));
    }
}
